package DomainLayer;
import java.util.ArrayList;

public class Stock
{
    private ArrayList<Items> items;
    private static Stock instance;
    
    private Stock()
    {
        items = new ArrayList<Items>();
    }
    
    //@return only one object of the calss Stock
    public static Stock getInstance(){
        if(instance==null){
            instance = new Stock();
        }
        return instance;
    }
    
    public void addItem(Items item){
        items.add(item);
    }
    
    public void deleteItem(Items item){
        items.remove(item);
    }
    
    //@return item which quantity is below required minimimum quantity
    public Items findItemBelowMinimum(){
        for(Items item:items){
            if(item.getMinimumAmount()>= item.getQuantity()){
                return item;
            }
        }
        return null;
    }
    
    //@return item according its bar code.
    public Items searchForItem(String barCode){
        for(Items item:items){
            if(item.getProduct().getBarCode().equals(barCode)){
                return item;
            }
        }
        return null;
    }
}